package com.ruoyi.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.ZhuanjiaBiandongPici;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ZhuanjiaBiandongDetailMapper;
import com.ruoyi.system.domain.ZhuanjiaBiandongDetail;
import com.ruoyi.system.service.IZhuanjiaBiandongDetailService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 专家变动详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Service
public class ZhuanjiaBiandongDetailServiceImpl implements IZhuanjiaBiandongDetailService 
{
    @Autowired
    private ZhuanjiaBiandongDetailMapper zhuanjiaBiandongDetailMapper;

    @Autowired
    private ZhuanjiaBiandongPiciServiceImpl zhuanjiaBiandongPiciService;

    /**
     * 查询专家变动详情
     * 
     * @param id 专家变动详情主键
     * @return 专家变动详情
     */
    @Override
    public ZhuanjiaBiandongDetail selectZhuanjiaBiandongDetailById(String id)
    {
        return zhuanjiaBiandongDetailMapper.selectZhuanjiaBiandongDetailById(id);
    }

    /**
     * 查询专家变动详情列表
     * 
     * @param zhuanjiaBiandongDetail 专家变动详情
     * @return 专家变动详情
     */
    @Override
    public List<ZhuanjiaBiandongDetail> selectZhuanjiaBiandongDetailList(ZhuanjiaBiandongDetail zhuanjiaBiandongDetail)
    {
        return zhuanjiaBiandongDetailMapper.selectZhuanjiaBiandongDetailList(zhuanjiaBiandongDetail);
    }

    /**
     * 新增专家变动详情
     * 
     * @param zhuanjiaBiandongDetail 专家变动详情
     * @return 结果
     */
    @Override
    public int insertZhuanjiaBiandongDetail(ZhuanjiaBiandongDetail zhuanjiaBiandongDetail)
    {
        return zhuanjiaBiandongDetailMapper.insertZhuanjiaBiandongDetail(zhuanjiaBiandongDetail);
    }

    /**
     * 修改专家变动详情
     * 
     * @param zhuanjiaBiandongDetail 专家变动详情
     * @return 结果
     */
    @Override
    public int updateZhuanjiaBiandongDetail(ZhuanjiaBiandongDetail zhuanjiaBiandongDetail)
    {
        return zhuanjiaBiandongDetailMapper.updateZhuanjiaBiandongDetail(zhuanjiaBiandongDetail);
    }

    /**
     * 批量删除专家变动详情
     * 
     * @param ids 需要删除的专家变动详情主键
     * @return 结果
     */
    @Override
    public int deleteZhuanjiaBiandongDetailByIds(String ids)
    {
        return zhuanjiaBiandongDetailMapper.deleteZhuanjiaBiandongDetailByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除专家变动详情信息
     * 
     * @param id 专家变动详情主键
     * @return 结果
     */
    @Override
    public int deleteZhuanjiaBiandongDetailById(String id)
    {
        return zhuanjiaBiandongDetailMapper.deleteZhuanjiaBiandongDetailById(id);
    }

    /**
     * 新增专家变动详情custom
     *
     * @param zhuanjiaBiandongDetail 专家变动详情
     * @return 结果
     */
    @Override
    @Transactional
    public boolean insertZhuanjiaBiandongDetailCustom(ZhuanjiaBiandongDetail zhuanjiaBiandongDetail)
    {
        boolean ok = true;

        if (zhuanjiaBiandongDetailMapper.insertZhuanjiaBiandongDetail(zhuanjiaBiandongDetail)!=1){
            ok = false;
            throw new RuntimeException("添加变动失败");
        }

        return ok;
    }

    public List<Map<String,Object>>selectZhuanjiaBiandongDetailListCustom(String ppDeptId,String ppZhuanjiamingcheng,String ppBiandongleixing,String ppBiandongriqi,int ppPageIndex,int ppPageSize){

        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;

        return zhuanjiaBiandongDetailMapper.selectZhuanjiaBiandongDetailListCustom(ppDeptId,ppZhuanjiamingcheng,ppBiandongleixing,ppBiandongriqi,mmStartIndex,ppPageSize);
    }

    public int countZhuanjiaBiandongDetailListCustom(String ppDeptId, String ppZhuanjiamingcheng,String ppBiandongleixing, String ppBiandongriqi){
        return zhuanjiaBiandongDetailMapper.countZhuanjiaBiandongDetailListCustom(ppDeptId,ppZhuanjiamingcheng,ppBiandongleixing,ppBiandongriqi);
    }

    //判断同一专家是否已存在没审核通过的变动
    public List<Map<String,Object>> existBiandongByZhuanjiaIdAndBeizhu1(String ppZhuanjiaId){
        return zhuanjiaBiandongDetailMapper.existBiandongByZhuanjiaIdAndBeizhu1(ppZhuanjiaId);
    }
    /**
     * 专家管理-当批次专家变动状态管理-历史专家变动查询-列表
     */
    public List<Map<String,Object>>lishizhuanjiabiandongList(String ppDeptId,String ppZhuanjiamingcheng,String ppBiandongleixing,String ppBiandongriqi,String danweimingcheng,String cengji,int ppPageIndex,int ppPageSize){

        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;

        return zhuanjiaBiandongDetailMapper.lishizhuanjiabiandongList(ppDeptId,ppZhuanjiamingcheng,ppBiandongleixing,ppBiandongriqi,danweimingcheng,cengji,mmStartIndex,ppPageSize);
    }

    public int lishizhuanjiabiandongListCount(String ppDeptId, String ppZhuanjiamingcheng,String ppBiandongleixing, String ppBiandongriqi,String danweimingcheng,String cengji){
        return zhuanjiaBiandongDetailMapper.lishizhuanjiabiandongListCount(ppDeptId,ppZhuanjiamingcheng,ppBiandongleixing,ppBiandongriqi,danweimingcheng,cengji);
    }
}
